package cn.wanda.bi.sunshine.platform.server.service.authorize;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import cn.wanda.bi.sunshine.platform.server.bean.KeyCache;
import cn.wanda.bi.sunshine.platform.server.controller.response.AdminLoginResponse;
import cn.wanda.bi.sunshine.platform.server.controller.response.MemberLoginResponse;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.SimpleResponse;

/**
 * Created by wangfupeng1
 */
@Service
public class AuthService {

	public static final Logger logger = LoggerFactory.getLogger(AuthService.class);

	@Autowired
	private WechatAuthService wechatAuthService;

	@Cacheable(value = "cache:wechat", key = "'cache:wechat:appid:'+#appid+':url:'+#url+':type:'+#type")
	public SimpleResponse memberSignature(String appid, String url, String type) {
		if (type.equals("WECHAT")) {
			return wechatAuthService.memberSignature(appid, url, type);
		}
		return SimpleResponse.success();
	}

	@Cacheable(value = "cache:wechat", key = "'cache:wechat:memberlogin:appid:'+#appid+':code:'+#code+':type:'+#type")
	public SimpleResponse memberLogin(String appid, String code, String type) {
		if (type.equals("WECHAT")) {
			return wechatAuthService.memberLogin(appid, code, type);
		}
		return SimpleResponse.success();
	}

	public SimpleResponse<MemberLoginResponse> memberBind(String appid, String code, String mobile,
			String verifyCode, String type) {
		if (type.equals("WECHAT")) {
			return wechatAuthService.memberBind(appid, code, mobile, verifyCode, type);
		}
		return SimpleResponse.success();
	}

	@Cacheable(value = "cache:wechat", key = "'cache:wechat:userinfo:appid:'+#appid+':code:'+#code+':type:'+#type")
	public SimpleResponse memberUserInfo(String appid, String code, String type) {
		if(type.equals("WECHAT")){
			return wechatAuthService.memberUserInfo(appid, code, type);
		}
		return SimpleResponse.success();
	}

	@Cacheable(value = "cache:wechat", key = "'cache:wechat:adminlogin:appid:'+#appid+':code:'+#code+':type:'+#type")
	public SimpleResponse<AdminLoginResponse> adminLogin(String appid, String code, String type) {
		if (type.equals("WECHAT")) {
			return wechatAuthService.adminLogin(appid, code, type);
		}
		return SimpleResponse.success();
	}
	
	public SimpleResponse adminBind(String appid, String code, String userName, String password, String type) {
		if (type.equals("WECHAT")) {
			return wechatAuthService.adminBind(appid, code, userName, password, type);
		}
		return SimpleResponse.success();
	}

}
